package com.example.ormsqlsplicingframe1.proxy;

import java.util.List;

public class EntityProxyService implements  TransactionListener{

    private SyncProxyFactory syncProxyFactory;

    private LazyProxyFactory lazyProxyFactory;


    //获取一个代理对象
    public Object getProxy(Object data){
       return syncProxyFactory.getProxy(data);
    }

    public List<Object> getList(){
       return syncProxyFactory.getProxyList();
    }


    public EntityProxyService(SyncProxyFactory syncProxyFactory, LazyProxyFactory lazyProxyFactory) {
        this.syncProxyFactory = syncProxyFactory;
        this.lazyProxyFactory = lazyProxyFactory;
    }

    public static EntityProxyService newInstance(){
        SyncProxyFactory syncProxyFactory = new SyncProxyFactory();
        LazyProxyFactory factory = new LazyProxyFactory(syncProxyFactory);
        return new EntityProxyService(syncProxyFactory,factory);
    }

    @Override
    public void startTransaction() {

    }

    @Override
    public void commitTransaction() {
        syncProxyFactory.commitTransaction();
    }

    @Override
    public void rollbackTransaction() {
        syncProxyFactory.rollbackTransaction();
    }
}
